/*******************************************************************************
				TABLE 3
*******************************************************************************/

*WAGE IV, COWORKERS
*TABLE 3, PANEL A: WEAK TIES
cap{
use "$data/table3A_weakties.dta", clear

global xi edad edad2 sexo anos_educ puntaje lnw
global xg m_l_edad m_l_sexo m_l_puntaje m_l_anos_educ

local dep l_net
local iv z_lnet
eststo clear

*1. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(rut_emp)
	eststo first_lnet

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(rut_emp)
	eststo rf_zlnet

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rut_emp)
	eststo iv_lnet
}
esttab first_lnet rf_zlnet iv_lnet, keep(`dep' `iv') ///
	mtitles("First Stage" "Reduced Form" "TSLS") ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N, fmt(%8.0fc) labels(Observations)) brackets ///
	coeflabels(l_net "Endogenous" z_lnet "Instrument") ///
	title("Table 3 Panel A. Wage Instrument: Peer effects in the coworker's network with stronger and weaker ties, 2010-2012. Former coworkers")
clear

*WAGE IV, COWORKERS
*TABLE 3, PANEL A: BASELINE
cap{
use "$data/base WAGE IV companies.dta", clear

global xi edad edad2 sexo anos_educ puntaje lnw
global xg m_l_edad m_l_sexo m_l_puntaje m_l_anos_educ

local dep l_net
local iv z_lnet

*1. REDUCED FORM:
eststo clear
qui reg sej2012 $xi $xg `iv', cluster(rut_emp)
	eststo rflnet_1012
		
*2. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(rut_emp)
	eststo first_lnet_1012
	cap test z_lnet
	estadd scalar Ft = r(F)

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rut_emp) 
	eststo ivlnet_1012
	}
	
esttab first_lnet_1012 rflnet_1012 ivlnet_1012, ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N Ft, fmt(%8.0fc %8.1fc) labels(Observations F))  ///
	brackets coeflabels(l_net "Endogenous" z_lnet "Instrument") ///
	keep(`dep' `iv') mtitles("First Stage" "Reduced Form" "TSLS") ///
	title("Table 3 Panel A. Wage Instrument: Effect of peers' adoption in 2009 on YES adoption during 2010-2012") 
clear

*WAGE IV, COWORKERS
*TABLE 3, PANEL A: STRONG TIES
cap{
use "$data/table3A_strongties.dta", clear

global xi edad edad2 sexo anos_educ puntaje lnw
global xg m_l_edad m_l_sexo m_l_puntaje m_l_anos_educ

local dep l_net
local iv z_lnet
eststo clear

*1. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(cownet)
	eststo first_lnet

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(cownet)
	eststo rf_zlnet
	
*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(cownet)
	eststo iv_lnet
}
esttab first_lnet rf_zlnet iv_lnet, keep(`dep' `iv') ///
	mtitles("First Stage" "Reduced Form" "TSLS") ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N, fmt(%8.0fc) labels(Observations)) brackets ///
	coeflabels(l_net "Endogenous" z_lnet "Instrument") ///
	title("Table 3 Panel A. Wage Instrument: Peer effects in the coworker's network with stronger and weaker ties, 2010-2012. Longer term coworkers")
clear

********************************************************************************

*AGE IV, COWORKERS
*TABLE 3, PANEL B: WEAK TIES
cap{
use "$data/table3B_weakties.dta", clear

global xi edad edad2 sexo lnw anos_educ puntaje
global xg m_l_sexo m_l_lnw m_l_anos_educ m_l_puntaje 

local dep lnet
local iv zlnet
eststo clear

*1. FIRST STAGE:
qui reg lnet $xi $xg `iv', cluster(rut_emp)
	eststo first_firm

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(rut_emp)
	eststo rf_firm

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rut_emp)
	eststo iv_firm
}
esttab first_firm rf_firm iv_firm, ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N, fmt(%8.0fc) labels(Observations))  ///
	brackets coeflabels(`dep' "Endogenous" `iv' "Instrument") ///
	keep(`dep' `iv') mtitles("First Stage" "Reduced Form" "TSLS") ///
	title("Table 3 Panel B. Age Instrument: Peer effects in the coworker's network with stronger and weaker ties, 2010-2012. Former coworkers")
clear

*AGE IV, COWORKERS
*TABLE 3, PANEL B: BASELINE
cap{
use "$data/base AGE IV.dta", clear

global xi edad edad2 sexo puntaje lnw anos_educ
global xg m_l_sexo m_l_puntaje m_l_anos_educ m_l_lnw

local dep lnet
local iv zlnet
eststo clear

*1. FIRST STAGE:
qui reg `dep' $xi $xg `iv', cluster(rut_emp)
	eststo first_firm
	test zlnet
	estadd scalar Ft = r(F)

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(rut_emp)
	eststo rf_firm

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(rut_emp)
	eststo iv_firm
}
esttab first_firm rf_firm iv_firm, ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N Ft, fmt(%8.0fc %8.1fc) labels(Observations F))  ///
	brackets coeflabels(`dep' "Endogenous" `iv' "Instrument") ///
	keep(`dep' `iv') mtitles("First Stage" "Reduced Form" "TSLS") ///
	title("Table 3 Panel B. Age Instrument: Effect of peers' adoption in 2009 on YES adoption during 2010-2012") 
clear


*AGE IV, COWORKERS
*TABLE 3, PANEL B: STRONG TIES
cap{
use "$data/table3B_strongties.dta", clear

global xi edad edad2 sexo lnw anos_educ puntaje
global xg mlsexo mllnw mlanos_educ mlpuntaje

local dep lnet
local iv zlnet
eststo clear

*1. FIRST STAGE:
qui reg lnet $xi $xg `iv', cluster(cownet)
	eststo first_firm

*2. REDUCED FORM:
qui reg sej2012 $xi $xg `iv', cluster(cownet)
	eststo rf_firm

*3. SECOND STAGE:
qui ivreg sej2012 $xi $xg (`dep' = `iv'), cluster(cownet)
	eststo iv_firm
}		
esttab first_firm rf_firm iv_firm, keep(`dep' `iv') ///
	mtitles("First Stage" "Reduced Form" "TSLS") ///
	b(%6.4fc) se(%6.4fc) star(* 0.1 ** 0.05 *** 0.01) ///
	stats(N, fmt(%8.0fc) labels(Observations)) brackets ///
	coeflabels(`dep' "Endogenous" `iv' "Instrument") ///
	title("Table 3 Panel B. Age Instrument: Peer effects in the coworker's network with stronger and weaker ties, 2010-2012. Longer term coworkers")
clear

